# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=todoman
pkgver=4.4.0
pkgrel=1
pkgdesc="A simple, standards-based, cli todo (aka: task) manager"
arch=(any)
url="https://github.com/pimutils/todoman"
license=(ISC)
depends=(
  python
  python-atomicwrites
  python-click
  python-click-log
  python-dateutil
  python-humanize
  python-icalendar
  python-parsedatetime
  python-pytz
  python-pyxdg
  python-urwid
)
makedepends=(
  python-build
  python-installer
  python-sphinx-autorun
  python-sphinx-click
  python-sphinx_rtd_theme
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  python-freezegun
  python-hypothesis
  python-pytest
  python-pytest-runner
)
optdepends=(
  'python-click-repl: REPL command'
)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('45e5272fe1a001894c7d86b2cea1ba3a3b41df7b9966952d622ba97e0474a3d490788953cf05fccce2f83ae5f5c8ecce9ecfc0f880dd23deb5f0ffe618c436e6')
b2sums=('f90208ad61d5aa1a9d546b998e4c640a8e5904587e8d1baf74189171521edb8ea19c5d15803edc72650b589076f89d6b5ed8779a0234bc46597ed9d023d0489e')

prepare() {
  # we don't care about test coverage
  sed '/addopts/d' -i $pkgname-$pkgver/pyproject.toml
}

build() {
  export SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver"

  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
  PYTHONPATH="$PYTHONPATH:$PWD" make -C docs man
}

check() {
  local pytest_options=(
    -vv
    --deselect tests/test_ui.py::test_ctrl_c_clears
  )

  cd $pkgname-$pkgver
  export PYTHONPATH="build:$PYTHONPATH"
  # tests require timezone to be set to UTC
  # https://github.com/pimutils/todoman/issues/404
  TZ="UTC" pytest "${pytest_options[@]}" tests/
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  # docs
  install -vDm 644 {AUTHORS,CHANGELOG,CODE_OF_CONDUCT,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
  # manpages
  install -vDm 644 docs/build/man/*.1 -t "$pkgdir/usr/share/man/man1/"
  # license
  # wrong name: https://github.com/pimutils/todoman/issues/319
  install -vDm 644 LICENCE -t "$pkgdir/usr/share/licenses/$pkgname/"
  # sample config
  install -vDm 644 "config.py.sample" -t "$pkgdir/usr/share/doc/$pkgname/examples/"
  # completions
  install -vDm 644 contrib/completion/bash/_todo "$pkgdir/usr/share/bash-completion/completions/todo"
  install -vDm 644 contrib/completion/zsh/_todo -t "$pkgdir/usr/share/zsh/site-functions/"
}
